package net.mingsoft.basic.exception;

import org.springframework.boot.autoconfigure.web.servlet.error.*;
import springfox.documentation.annotations.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.boot.web.servlet.error.*;
import org.springframework.boot.autoconfigure.web.*;
import org.slf4j.*;
import javax.servlet.http.*;
import org.springframework.web.servlet.*;
import java.util.*;
import net.mingsoft.base.entity.*;
import org.springframework.http.*;
import cn.hutool.core.bean.*;

@ApiIgnore
@Controller
@RequestMapping(value = { "${server.error.path:${error.path:/error}}" }, method = { RequestMethod.GET, RequestMethod.POST })
public class ErrorController extends BasicErrorController
{
    protected final Logger LOG;
    
    public ErrorController(final ErrorAttributes errorAttributes) {
        super(errorAttributes, new ErrorProperties());
        this.LOG = LoggerFactory.getLogger((Class)this.getClass());
    }
    
    public ModelAndView errorHtml(final HttpServletRequest request, final HttpServletResponse response) {
        final HttpStatus status = this.getStatus(request);
        final Map<String, Object> model = Collections.unmodifiableMap((Map<? extends String, ?>)this.getErrorAttributes(request, this.getErrorAttributeOptions(request, MediaType.TEXT_HTML)));
        response.setStatus(status.value());
        final ModelAndView modelAndView = this.resolveErrorView(request, response, status, (Map)model);
        this.LOG.debug("errorhtml log meseeage\uff1a{},url\uff1a{}", model.get("message"), model.get("path"));
        return (modelAndView != null) ? modelAndView : new ModelAndView("/error/index", (Map)ResultData.build().code(model.get("status").toString()).msg(model.get("error").toString()));
    }
    
    public ResponseEntity<Map<String, Object>> error(final HttpServletRequest request) {
        final HttpStatus status = this.getStatus(request);
        if (status == HttpStatus.NO_CONTENT) {
            return (ResponseEntity<Map<String, Object>>)new ResponseEntity(status);
        }
        final Map<String, Object> body = (Map<String, Object>)this.getErrorAttributes(request, this.getErrorAttributeOptions(request, MediaType.ALL));
        this.LOG.debug("error status {}, error {},url {}", new Object[] { status, body, request.getRequestURI() });
        BeanUtil.copyProperties((Object)ResultData.build().code(status).msg(body.get("error").toString()), (Object)body, new String[0]);
        return (ResponseEntity<Map<String, Object>>)new ResponseEntity((Object)body, status);
    }
}
